home *** CD-ROM | disk | FTP | other *** search
/ SPACE 1 / SPACE - Library 1 - Volume 1.iso / program / 363 / xlisp20 / xlisp_c / xlisp.c < prev    next >
Text File  |  1990-02-03  |  2KB  |  100 lines

  1. /* xlisp - an small version of lisp that supports object-oriented programming */
  2. /*    Copyright (c) 1985, by David Michael Betz
  3.     All Rights Reserved
  4.     Permission is granted for unrestricted non-commercial use    */
  5.  
  6. #include "xlisp.h"
  7.  
  8. /* define the banner line string */
  9. #define BANNER    "XLISP version 1.5b, Copyright (c) 1985, by David Betz"
  10.  
  11. /* external variables */
  12. extern NODE *s_stdin,*s_stdout;
  13. extern NODE *s_evalhook,*s_applyhook;
  14. extern NODE *true;
  15.  
  16. /* main - the main routine */
  17. main(argc,argv)
  18.   int argc; char *argv[];
  19. {
  20.     char fname[50];
  21.     CONTEXT cntxt;
  22.     NODE expr;
  23.     int i;
  24.  
  25.     /* print the banner line */
  26. #ifdef MEGAMAX
  27.     macinit(BANNER);
  28. #else
  29.     printf("%s\n",BANNER);
  30. #endif
  31.  
  32.     /* setup initialization error handler */
  33.     xlbegin(&cntxt,CF_ERROR,(NODE *) 1);
  34.     if (setjmp(cntxt.c_jmpbuf)) {
  35.     printf("fatal initialization error\n");
  36.     exit();
  37.     }
  38.  
  39.     /* initialize xlisp */
  40.     xlinit();
  41.     xlend(&cntxt);
  42.  
  43.     /* reset the error handler */
  44.     xlbegin(&cntxt,CF_ERROR,true);
  45.  
  46.     /* load "init.lsp" */
  47.     if (setjmp(cntxt.c_jmpbuf) == 0)
  48.     xlload("init.lsp",FALSE,FALSE);
  49.  
  50.     /* load any files mentioned on the command line */
  51. #ifndef MEGAMAX
  52.     if (setjmp(cntxt.c_jmpbuf) == 0)
  53.     for (i = 1; i < argc; i++) {
  54.         sprintf(fname,"%s.lsp",argv[i]);
  55.         if (!xlload(fname,TRUE,FALSE))
  56.         xlfail("can't load file");
  57.     }
  58. #endif
  59.  
  60.     /* create a new stack frame */
  61.     xlsave(&expr,NULL);
  62.  
  63.     /* main command processing loop */
  64.     while (TRUE) {
  65.  
  66.     /* setup the error return */
  67.     if (setjmp(cntxt.c_jmpbuf)) {
  68.         setvalue(s_evalhook,NIL);
  69.         setvalue(s_applyhook,NIL);
  70.         xlflush();
  71.     }
  72.  
  73.     /* read an expression */
  74.     if (!xlread(getvalue(s_stdin),&expr.n_ptr))
  75.         break;
  76.  
  77.     /* evaluate the expression */
  78.     expr.n_ptr = xleval(expr.n_ptr);
  79.  
  80.     /* print it */
  81.     stdprint(expr.n_ptr);
  82.     }
  83.     xlend(&cntxt);
  84. }
  85.  
  86. /* stdprint - print to standard output */
  87. stdprint(expr)
  88.   NODE *expr;
  89. {
  90.     xlprint(getvalue(s_stdout),expr,TRUE);
  91.     xlterpri(getvalue(s_stdout));
  92. }
  93.  
  94. /* stdputstr - print a string to standard output */
  95. stdputstr(str)
  96.   char *str;
  97. {
  98.     xlputstr(getvalue(s_stdout),str);
  99. }
  100. əəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəə